package com.yc.http.adapter;

public class Lazyman {
    public class LazyMan {



        //构造器私有
        private LazyMan(){
            System.out.println(Thread.currentThread().getName()+"OK");
        }

        //初始化对象
        private volatile static LazyMan lazyMan=null;


        //双重检测锁模式的 懒汉式单例 -> DCL懒汉式
        public static LazyMan getInstance(){
            if (lazyMan==null){
                synchronized (LazyMan.class){
                    if (lazyMan==null){
                        lazyMan = new LazyMan();
                    }
                }
            }
            return lazyMan;
        }

        //跑10个线程
        public static void main(String[] args) {
            for (int i = 0; i < 10; i++) {
                new Thread(()->{
                    lazyMan.getInstance();
                }).start();
            }
        }




    }
}
